﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameSDK.Player;
using CounterGame.Board;
using System.Timers;


namespace CounterGame.Player
{
    public class CounterStrategy : IStdStrategy
    {

        #region Attributes
        private StdPlayer player;
        private CounterBoard counter;

        private int val;

        private Timer timer;

        #endregion

        #region Constructor
        public CounterStrategy(StdPlayer _player)
        {
            this.player = _player;
            counter = (CounterBoard)_player.Board;

            timer = new Timer();
            timer.Interval = 1;
            timer.Enabled = true;
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            
        }

        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Stop();
            if (val == (CounterBoard.VALEUR_MAX))
            {
                Console.WriteLine("Fin du Jeu....");
            }
            else
            {
                counter.PlayerMoved(player, new StdMove());
            }

        }
        #endregion

        public void DoMove()
        {
            timer.Start();
            //timer.

            val = counter.CurrentVal + 1;
            string Value = "Player " + player.GamePlayerId + " - " + val;
            Console.WriteLine(Value);
            counter.CurrentVal = val;

            //if (val == (CounterBoard.VALEUR_MAX))
            //{
            //    Console.WriteLine("Fin du Jeu....");
            //}
            //else
            //{
            //    counter.PlayerMoved(player, new StdMove());
            //}

            
        }
    }
}
